package org.example.spring.simple.framework.aop.intercept;

import org.example.spring.simple.framework.aop.aspect.ZAbstractAspectJAdvice;
import org.example.spring.simple.framework.aop.aspect.ZAdvice;
import org.example.spring.simple.framework.aop.aspect.ZJoinPoint;

import java.lang.reflect.Method;

public class ZAfterReturningAdviceInterceptor extends ZAbstractAspectJAdvice implements ZAdvice, ZMethodInterceptor {
    private ZJoinPoint joinPoint;

    public ZAfterReturningAdviceInterceptor(Method method, Object target) {
        super(method, target);
    }

    @Override
    public Object invoke(ZMethodInvocation invocation) throws Throwable {
        Object returnValue = invocation.proceed();
        this.joinPoint = invocation;
        this.afterReturning(returnValue, invocation.getMethod(), invocation.getArguments(), invocation.getThis());
        return returnValue;
    }

    public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
        invokeAdviceMethod(joinPoint, returnValue, null);
    }
}
